<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 定义一个由数值组成的数组，根据该数组创建一个新数组，新数组的成员是原数组成员的二倍值。
    let a1 = [1, 2, 3, 4, 5];

    let newArr = [];
    for (let v of a1) {
        newArr.push(v * 2);
    }

    console.log("newArr = ", newArr);

    // 消除for循环
    newArr = [];
    a1.forEach(function(v) {
        newArr.push(v * 2);
    })
    console.log("newArr = ", newArr);

    // ES6 箭头函数
    newArr = [];
    a1.forEach(v => newArr.push(v * 2))
    console.log("newArr = ", newArr);

    let newArr2 = a1.map(v => v * 2);
    console.log("newArr2 = ", newArr2);

</script>

</html>